SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE [dbo].[ServiceInfoIsExist]
    @Name VARBINARY(MAX) ,
    @UserInfoId UNIQUEIDENTIFIER ,
    @ServiceTypeId UNIQUEIDENTIFIER ,
    @Id UNIQUEIDENTIFIER
AS 
    BEGIN
        IF ( @Id = NULL ) 
            BEGIN
                SELECT  COUNT(*)
                FROM    ServiceInfo
                WHERE   Name = @Name
                        AND UserInfoId = @UserInfoId
                        AND ServiceTypeId = @ServiceTypeId
                        AND DELETED = 0
            END
        ELSE 
            BEGIN
                SELECT  COUNT(*)
                FROM    ServiceInfo
                WHERE   Name = @Name
                        AND UserInfoId = @UserInfoId
                        AND ServiceTypeId = @ServiceTypeId
                        AND Id != @Id
                        AND DELETED = 0
            END
    END

GO
